package com.examples.ry.layouts;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Sash;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class FormLayoutSashPane {

	public static void main(String[] args) {
		Display display = Display.getDefault();
		final Shell shell = new Shell(display);
		int style = SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL;
		List list = new List(shell, style);
		list.setItems(new String[] { "One", "Two", "Three" });
		Sash sash = new Sash(shell, SWT.VERTICAL);
		Text text = new Text(shell, style);
		/* Create a FormLayout to configure the Sash */
		FormLayout layout = new FormLayout();
		shell.setLayout(layout);
		FormData listData = new FormData();
		listData.left = new FormAttachment(0);
		listData.right = new FormAttachment(sash);
		listData.top = new FormAttachment(0);
		listData.bottom = new FormAttachment(100);
		list.setLayoutData(listData);
		final FormData sashData = new FormData();
		sashData.left = new FormAttachment(30);
		sashData.top = new FormAttachment(0);
		sashData.bottom = new FormAttachment(100);
		sash.setLayoutData(sashData);
		sash.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event event) {
				if (event.detail != SWT.DRAG) {
					sashData.left = new FormAttachment(0, event.x);
					shell.layout();
				}
			}
		});
		FormData data2 = new FormData();
		data2.left = new FormAttachment(sash);
		data2.right = new FormAttachment(100);
		data2.top = new FormAttachment(0);
		data2.bottom = new FormAttachment(100);
		text.setLayoutData(data2);
		shell.pack();
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}		
	}

}
